/**
 * 
 */
package cz.cuni.mff.abacs.burglar.logics.objects.positions;

import cz.cuni.mff.abacs.burglar.logics.DataMap;
import cz.cuni.mff.abacs.burglar.logics.objects.BaseInterface;
import cz.cuni.mff.abacs.burglar.logics.objects.BaseObject;
import cz.cuni.mff.abacs.burglar.logics.objects.Room;


/**
 * Static guardians of the environment.
 * 
 * @author abacs
 *
 */
public class Camera extends BasePosition implements Position, Active {

	
	/**
	 * Changeable property. */
	boolean _isActive = true;
	
	
	// -------------------------------------------------------------------------
	
	
	/**
	 * 
	 * @param id
	 * @param x
	 * @param y
	 * @param room
	 * @param isActive
	 * @param referenceMap
	 */
	public Camera(
			int id,
			int x,
			int y,
			Room room,
			boolean isActive,
			DataMap referenceMap
	) {
		super(id, BaseObject.Type.CAMERA, x, y, false, room, referenceMap);
		this._isActive = isActive;
	}
	
	
	/**
	 * 
	 * @param id
	 * @param x
	 * @param y
	 * @param room
	 * @param isActive
	 * @param referenceMap
	 */
	public Camera(
			int id,
			int x,
			int y,
			int roomId,
			boolean isActive,
			DataMap referenceMap
	) {
		super(id, BaseObject.Type.CAMERA, x, y, false, roomId, referenceMap);
		this._isActive = isActive;
	}
	
	
	/**
	 * 
	 * @param other
	 * @param referenceMap
	 */
	protected Camera(Camera other, DataMap referenceMap) {
		super(other, referenceMap);
		this._isActive = other._isActive;
		
		
	}
	
	
	// -------------------------------------------------------------------------
	
	
	@Override
	public boolean isActive() {
		return this._isActive;
	}
	
	
	@Override
	public boolean changeActiveState() {
		this._isActive = ! this._isActive;
		return this._isActive;
	}
	
	
	@Override
	public boolean activate() {
		this._isActive = true;
		return true;
	}
	
	
	@Override
	public boolean deactivate() {
		this._isActive = false;
		return true;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	@Override
	public boolean isOperable() {
		return true;
	}
	
	
	@Override
	public boolean isTrap() {
		return this._isActive;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	/**
	 * From far the agent can't see whether the camera is active.
	 */
	@Override
	public Position examinedFromFar() {
		return new Camera(
				this.getId(),
				this.getX(),
				this.getY(),
				this._roomId,
				false,
				null
			);
	}
	
	
	/**
	 * From near the agent can see whether the camera is active.
	 */
	@Override
	public Position examinedFromNear() {
		return new Camera(
				this.getId(),
				this.getX(),
				this.getY(),
				this._roomId,
				this._isActive,
				null
			);
	}
	
	
	@Override
	public boolean matchesFromFar(Position position) {
		return 
			super.matches(position);
	}
	
	
	@Override
	public boolean matchesFromClose(Position position) {
		return
			super.matches(position) &&
			this._isActive == ((Camera)position)._isActive;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	@Override
	public void copyChangeables(Position original) {
		assert(original.isTypeOf(BaseInterface.Type.CAMERA));
		Camera original_ =  (Camera)original;
		this._isActive = original_._isActive;
	}
	
	
	@Override
	public Position copy(DataMap reference) {
		return new Camera(this, reference);
	}
	
	
}
